package dk.pekilidi.dod;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import java.io.Serializable;
import java.util.Date;

/**
 * User: mpeki
 * Date: 12-12-2007
 * Time: 21:37:56
 */
public abstract class BaseObject implements Serializable {

    private long id;
    private Date createdOn;
    private String description;
    private DoDType type;

    public BaseObject(){
        createdOn = new Date();
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public Date getCreatedOn() {
        return createdOn;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public DoDType getType() {
        return type;
    }

    public void setType(DoDType type) {
        this.type = type;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof BaseObject)) return false;

        BaseObject that = (BaseObject) o;

        if (id != that.id) return false;
        if (type != that.type) return false;
        if (createdOn != null ? !createdOn.equals(that.createdOn) : that.createdOn != null) return false;
        return !(description != null ? !description.equals(that.description) : that.description != null);

    }

    public int hashCode() {
        int result;
        result = (int) (id ^ (id >>> 32));
        result = 31 * result + (createdOn != null ? createdOn.hashCode() : 0);
        result = 31 * result + (description != null ? description.hashCode() : 0);
        result = 31 * result + (type != null ? type.hashCode() : 0);
        return result;
    }


    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).
                append("id", id).
                append("createdOn", createdOn).
                append("description", description).
                append("type", type).
                toString();
    }
}
